/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto;

import javax.swing.JOptionPane;
import javax.swing.plaf.DesktopPaneUI;

/**
 *
 * @author mario
 */
public class frmSeleccionarUnidad extends javax.swing.JInternalFrame {

    frmInsertarNotaIntroFisica frmInsertarIntro;
    frmInsertarNotaIntroFisica2 frmInsertarIntro2;
    frmInsertarNotaIntroFisica3 frmInsertarIntro3;
    frmInsertarNotaIntroFisica4 frmInsertarIntro4;
    frmPpal frmppal;

    /**
     * Creates new form frmSeleccionarUnidad
     */
    public frmSeleccionarUnidad() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlblUnidad = new javax.swing.JLabel();
        jcmbUnidad = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();

        setClosable(true);

        jlblUnidad.setText("Unidad:");

        jcmbUnidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "[ SELECCIONE ]", "Unidad I", "Unidad II", "Unidad III", "Unidad IV" }));
        jcmbUnidad.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbUnidadItemStateChanged(evt);
            }
        });

        jButton2.setText("Aceptar");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jlblUnidad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addComponent(jcmbUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
            .addGroup(layout.createSequentialGroup()
                .addGap(126, 126, 126)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcmbUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblUnidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2MouseClicked

    private void jcmbUnidadItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbUnidadItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jcmbUnidadItemStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        //validando la primera unidad
        if (jcmbUnidad.getSelectedItem().equals("Unidad I")) {
            if (frmInsertarIntro == null || frmInsertarIntro.isClosed()) {
                frmInsertarIntro = new frmInsertarNotaIntroFisica();
                //Para habilitar el desktopPane tuve que hacerlo public en "Personalizar" codigo en el ppal
                frmPpal.desktopPane.add(frmInsertarIntro);
                frmInsertarIntro.show();
                frmInsertarIntro.toFront();
                this.dispose();

            } else {
                JOptionPane.showMessageDialog(rootPane, "La ventana ya se encuentra abierta", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
            //Validando la 2da unidad
        }else if(jcmbUnidad.getSelectedItem().equals("Unidad II")){
             if (frmInsertarIntro2 == null || frmInsertarIntro2.isClosed()) {
                frmInsertarIntro2 = new frmInsertarNotaIntroFisica2();
                //Para habilitar el desktopPane tuve que hacerlo public en "Personalizar" codigo en el ppal
                frmPpal.desktopPane.add(frmInsertarIntro2);
                frmInsertarIntro2.show();
                frmInsertarIntro2.toFront();
                this.dispose();

            } else {
                JOptionPane.showMessageDialog(rootPane, "La ventana ya se encuentra abierta", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
             //Validando la 3ra unidad
        }else if(jcmbUnidad.getSelectedItem().equals("Unidad III")){
             if (frmInsertarIntro3 == null || frmInsertarIntro3.isClosed()) {
                frmInsertarIntro3 = new frmInsertarNotaIntroFisica3();
                //Para habilitar el desktopPane tuve que hacerlo public en "Personalizar" codigo en el ppal
                frmPpal.desktopPane.add(frmInsertarIntro3);
                frmInsertarIntro3.show();
                frmInsertarIntro3.toFront();
                this.dispose();

            } else {
                JOptionPane.showMessageDialog(rootPane, "La ventana ya se encuentra abierta", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        //Validando la 4ta unidad
        }else if(jcmbUnidad.getSelectedItem().equals("Unidad IV")){
             if (frmInsertarIntro4 == null || frmInsertarIntro4.isClosed()) {
                frmInsertarIntro4 = new frmInsertarNotaIntroFisica4();
                //Para habilitar el desktopPane tuve que hacerlo public en "Personalizar" codigo en el ppal
                frmPpal.desktopPane.add(frmInsertarIntro4);
                frmInsertarIntro4.show();
                frmInsertarIntro4.toFront();
                this.dispose();

            } else {
                JOptionPane.showMessageDialog(rootPane, "La ventana ya se encuentra abierta", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        }

    }//GEN-LAST:event_jButton2ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jcmbUnidad;
    private javax.swing.JLabel jlblUnidad;
    // End of variables declaration//GEN-END:variables
}
